package net.ib.mtalk.ui.attachment.vcard;

import java.util.List;

import net.ib.mtalk.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 주소록 아이템 리스트를 보여준다.
 * 
 * @author happy2v
 *
 */
public class VCardReadAdapter extends BaseAdapter {

	private Context mContext;
	private List<VCardListItemStruct> mItems;
	
	public VCardReadAdapter(Context context, List<VCardListItemStruct> items){
		this.mContext = context;
		this.mItems = items;
	}
	
	public View newView(Context context, ViewGroup parent){
		LayoutInflater inflater = LayoutInflater.from(context);
		View view = inflater.inflate(R.layout.list_item_vcard_read, parent, false);
		
		ViewHolder holder = new ViewHolder();
		holder.vcardTitle = (TextView) view.findViewById(R.id.vcard_title);
		holder.vcardSubTitle = (TextView) view.findViewById(R.id.vcard_sub_text);
		holder.vcardItemIcon = (ImageView) view.findViewById(R.id.vcard_item_icon);
		
		view.setTag(holder);
		return view;
	}
	
	private static class ViewHolder{
		TextView vcardTitle;
		TextView vcardSubTitle;
		ImageView vcardItemIcon;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view;
		if(convertView == null){
			view = newView(mContext, parent);
		}else{
			view = convertView;
		}
		ViewHolder holder = (ViewHolder)view.getTag();
		
//		bindView(view, mContext, mItems.get(position));
		final VCardListItemStruct item = mItems.get(position);
		
		holder.vcardTitle.setText(item.title);
		holder.vcardSubTitle.setText(item.subTitle);
				
		switch(item.type){
			case ContactStruct.KIND_EMAIL:
				holder.vcardItemIcon.setVisibility(View.VISIBLE);
				holder.vcardItemIcon.setImageResource(R.drawable.vcard_email_icon);
				break;
			case ContactStruct.KIND_EVENT:
				holder.vcardItemIcon.setVisibility(View.GONE);
				break;
			case ContactStruct.KIND_GROUP_MEMBERSHIP:
				holder.vcardItemIcon.setVisibility(View.GONE);
				break;
			case ContactStruct.KIND_IM:
				holder.vcardItemIcon.setVisibility(View.VISIBLE);
				holder.vcardItemIcon.setImageResource(R.drawable.vcard_im_icon);
				break;
			case ContactStruct.KIND_NAME:
				holder.vcardItemIcon.setVisibility(View.GONE);
				break;
			case ContactStruct.KIND_NICKNAME:
				holder.vcardItemIcon.setVisibility(View.GONE);
				break;
			case ContactStruct.KIND_NOTE:
				holder.vcardItemIcon.setVisibility(View.VISIBLE);
				holder.vcardItemIcon.setImageResource(R.drawable.vcard_note_icon);
				break;
			case ContactStruct.KIND_ORGANIZATION:
				holder.vcardItemIcon.setVisibility(View.VISIBLE);
				holder.vcardItemIcon.setImageResource(R.drawable.vcard_organization_icon);
				break;
			case ContactStruct.KIND_PHONE:
				holder.vcardItemIcon.setVisibility(View.VISIBLE);
				holder.vcardItemIcon.setImageResource(R.drawable.vcard_phone_icon);
				break;
			case ContactStruct.KIND_PHOTO:
				holder.vcardItemIcon.setVisibility(View.GONE);
				break;
			case ContactStruct.KIND_POSTAL:
				holder.vcardItemIcon.setVisibility(View.VISIBLE);
				holder.vcardItemIcon.setImageResource(R.drawable.vcard_postal_icon);
				break;
			case ContactStruct.KIND_RELATION:
				holder.vcardItemIcon.setVisibility(View.GONE);
				break;
			case ContactStruct.KIND_SIP_ADDRESS:
				holder.vcardItemIcon.setVisibility(View.GONE);
				break;
			case ContactStruct.KIND_WEBSITE:
				holder.vcardItemIcon.setVisibility(View.GONE);
				break;
			default:
				holder.vcardItemIcon.setVisibility(View.GONE);
				break;
		}
		
		return view;
	}
	
	@Override
	public int getCount() {
		return mItems.size();
	}

	@Override
	public VCardListItemStruct getItem(int position) {
		return mItems.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
}
